package bishi.day23_5_20;

/**
 * @author 是阿秋啊
 * @date 2022/05/21 14:33
 **/
public class hong_bao {
    public int getValue(int[] gifts, int n) {
        // write code here
        int max = gifts[0];
        int count = 1;
        for (int i = 1; i < n; i++) {
            if (count == 0) {
                count = 1;
                max = gifts[i];
            } else {
                if (max != gifts[i]) {
                    count--;
                }else {
                    count++;
                }
            }
        }
        int size = 0;
        for(int i = 0; i < n; i++) {
            if(gifts[i] == max) {
                size++;
            }
        }
        return size > n / 2 ? max : 0;
    }
}
